<?php
	if ((!defined("ADMIN-AREA")) || (!in_array(SHOWVIEW,$_SESSION['access']))) {
		die("No data");
	} else {
		unset($_SESSION['access']);
	}
	
	include_once "modul/funct_stat.php";
		
	function getSub($id_dirkat,$dataX,$ssX,$num) {
		$x = 1;
		$cekX[0] = "";
		$numx = $num;
		$sql1 = "SELECT * FROM ikadir_kat WHERE id_dirkatsub='".$id_dirkat."' ORDER BY id_dirkat";
		$qry1 = mysql_query($sql1);
		while ($row1 = mysql_fetch_object($qry1)) {
			$sql2 = "SELECT * FROM ikadir_kat WHERE id_dirkatsub='".$row1->id_dirkat."' ORDER BY id_dirkat";
			$qry2 = mysql_query($sql2);
			$row2 = mysql_num_rows($qry2);
			$spasi = "";
			for ($c=1;$c<=$ssX;$c++) {
				$spasi .= "&nbsp;&nbsp;&nbsp;";
			}
			
			if ($row2==0) {
				$images = "images/plus.png";
			} else {
				$images = "images/dir.png";
			}
			
			$data = $x%2;
			if ($dataX=="genap") {
				if ($data==0)
					$dataX = "genap";
				else
					$dataX = "ganjil";
			} else {
				$dataX = "genap";
			}
			
			$cekX[0] .= '<tr>';
			$cekX[0] .= '<td valign="middle" width="215"><table width="100%" border="0" cellspacing="2" cellpadding="4">
      <tr>
        <td width="12" valign="middle" nowrap="nowrap"><div align="left">'.$spasi.'<img src="'.$images.'" width="10" height="10" />&nbsp;</div></td>
        <td valign="middle"><span align="left" title=" URl : '.$row1->url.'"><strong>'.$row1->dir_kat.'</strong></span></td>
        </tr>
    </table></td>
    		<td width="110"><div align="center"><strong>'.$row1->id_dirkat.'</strong></div></td>';
			$cekX[0] .= '<th width="115"><div align="center">'.$row1->tipe.'</div></th>';
			$cekX[0] .= '<td width="115"><div align="center">';
			if (($row1->publish)==1) {
				$cekX[0] .= "<img src=\"images/ico_check.gif\" width=\"16\" height=\"16\"></div></td>";
			} else {
				$cekX[0] .= "<img src=\"images/ico_delete.gif\" width=\"16\" height=\"16\"></div></td>";
			}
			$cekX[0] .= '</div></td>';
			$cekX[0] .= '<td nowrap="nowrap"><div align="center"><a title="Edit" href="?show='.SHOW.'&amp;showview='.SHOWVIEW.'&amp;act=edit&amp;kode='.$row1->id_dirkat.'"><img title="Edit" src="images/edit.png" alt="Edit" width="16" height="16" border="0" /></a>&nbsp;<a onclick="return conf1(\'Are you sure delete this data?\')" title="Hapus" href="modul/directory/ver_directory.php?show='.SHOW.'&amp;showview='.SHOWVIEW.'&amp;kode='.$row1->id_dirkat.'&amp;act_ver=Hapus"><img title="Delete" src="images/delete.png" width="16" height="16" alt="Del" border="0" /></a></div></td>';
			$cekX[0] .= '</tr>';

			$v = getSub($row1->id_dirkat,$dataX,($ssX+2),$num);
			$cekX[0] .= $v[0];
			$num++;
			$z++;
		}
		
		return $cekX;
		
	}
	
	if (ACT=="edit") {
		$kode = (int) $_GET['kode'];
		$rowQ = $queryData->selek1("ikadir_kat","id_dirkat='".$kode."'");
		$kategoriX = $rowQ->dir_kat;
		$subkategoriX = $rowQ->id_dirkatsub;
		$picture = $rowQ->picture;
		$description = $rowQ->description;
		$publish = $rowQ->publish;
		$tipe = $rowQ->tipe;
		$url = $rowQ->url;
		
		$form_stat = "Edit";
	} else {
		$form_stat = "Input";
	}
	
	if ((ACT=="tambah") || (ACT=="edit")) {
?>
<form action="<?php echo $path; ?>ver_directory.php?show=<?php echo SHOW; ?>&amp;showview=<?php echo SHOWVIEW; ?>" method="post" enctype="multipart/form-data" name="form1" onsubmit="MM_validateForm('<?php echo $DIRECTORY_TITLE; ?>','','R','<?php echo $DIRECTORY_TYPE; ?>','','R');return document.MM_returnValue">
  <table width="600" border="0" align="center" cellpadding="4" cellspacing="2">
    <tr>
      <td width="25%" valign="middle"><div align="right"><?php echo $DIRECTORY_TITLE; ?></div></td>
      <td width="10" valign="middle"><div align="center">:</div></td>
      <td valign="middle"><div align="left">
        <input name="kategori" type="text" id="<?php echo $DIRECTORY_TITLE; ?>" value="<?php echo $kategoriX; ?>" size="30" class="input-title" />
      </div></td>
    </tr>
    <tr>
			<td valign="top"><div align="right"><?php echo $DIRECTORY_TYPE; ?></div></td>
    	<td><div align="center">:</div></td>
    	<td><div align="left">
    	  <select name="type" id="<?php echo $DIRECTORY_TYPE; ?>" style="width:100px">
    	    <?php
				$sqlQ = "SELECT * FROM tbl_kategori WHERE tipe='tipe_menu'";
				$qryQ = mysql_query($sqlQ);
				while ($rowQ = mysql_fetch_object($qryQ)) {
					echo '<option value="'.$rowQ->kategori.'"';
					if ($rowQ->kategori==$tipe)
						echo ' selected';
					echo '>'.$rowQ->kategori.'</option>';
				}
			?>
  	    </select>
   	  </div></td>
   	</tr>
    <tr>
      <td valign="top"><div align="right"><?php echo $DIRECTORY_SUB; ?></div></td>
      <td><div align="center">:</div></td>
      <td><div align="left">
        <select name="subkategori" id="<?php echo $DIRECTORY_SUB; ?>" style="width:200px">
          <option value="0">- <?php echo $DIRECTORY_BASE; ?></option>
      <?php
	  	echo subkategori(0,0,$subkategoriX,$kode,"",true);
	  ?>
        </select>
      </div></td>
    </tr>
    <tr>
      <td valign="top"><div align="right"><?php echo $DIRECTORY_DESC; ?></div></td>
      <td valign="top"><div align="center">:</div></td>
      <td valign="top"><div align="left">
        <textarea name="deskripsi" cols="60" rows="5" id="<?php echo $DIRECTORY_DESC; ?>"><?php echo $description; ?></textarea>
      </div></td>
    </tr>
    <tr>
      <td valign="top"><div align="right"><?php echo $DIRECTORY_URl; ?></div></td>
      <td valign="top"><div align="center">:</div></td>
      <td valign="top"><div align="left">
        <input name="url" type="text" id="<?php echo $DIRECTORY_URl; ?>" value="<?php echo $url; ?>" size="40" />
      </div></td>
    </tr>
    <tr valign="top">
      <td><div align="right"><?php echo $DIRECTORY_PUBLISH; ?></div></td>
      <td><div align="center">:</div></td>
      <td><div align="left">
        <input name="publish" type="checkbox" <?php	($publish=="1") ? print "checked" : print ""; ?>
 id="publish" value="ya" /> <?php echo $DEV_YES; ?>
      </div></td>
    </tr>
    <tr>
      <td valign="top"><div align="right"></div></td>
      <td>&nbsp;</td>
      <td><p align="left">
        <input type="submit" name="submit" id="submit" value="<?php echo $DEV_CTRL_SUBMIT; ?>" />
          <input type="reset" name="Reset" value="<?php echo $DEV_CTRL_RESET; ?>" />
        <input name="act_ver" type="hidden" id="act_ver" value="<?php echo strtolower($form_stat); ?>">
          <input name="kode" type="hidden" id="kode" value="<?php echo (int) $_GET['kode']; ?>">
</p>      </td>
    </tr>
  </table>
</form>
<?php
	} else {
		echo $queryData->cari_form($DIRECTORY_SEARCH);
		$caridata = $queryData->cari_padaku("dir_kat","tipe");
		($caridata) ? $a = '1 '.$caridata : $a = "id_dirkatsub='0'";
		
		if (isset($_SESSION['isroot'])) {
			$sql1 = "SELECT * FROM ikadir_kat WHERE ".$a." ORDER BY id_dirkat DESC LIMIT ".$limitdown.",10";
		} else {
			$sql1 = "SELECT * FROM ikadir_kat WHERE ".$a." ORDER BY id_dirkat DESC LIMIT ".$limitdown.",10";
		}		
?>
<table border="0" align="center" cellpadding="4" cellspacing="2" class="imagesSUB">
  <tr>
    <th width="200" height="30" class="imagesSUB"><div align="center"><?php echo $DIRECTORY_TITLE; ?></div>      
    	<div align="center"></div></th>
    <th width="50" class="imagesSUB"><div align="center"><?php echo $DIRECTORY_ID; ?></div></th>
    <th width="100" class="imagesSUB"><div align="center"><?php echo $DIRECTORY_TYPE; ?></div></th>
    <th width="83" class="imagesSUB"><div align="center"><?php echo $DIRECTORY_PUBLISH; ?></div></th>
    <th width="50" class="imagesSUB" ><div align="center"><?php echo $DEV_ACTION; ?></div></th>
  </tr>
  <?php
		$qry1 = mysql_query($sql1);
		$numrow = mysql_num_rows($qry1);
		if ($numrow==0) {
			echo '<tr><th colspan="7">'.$DEV_NO_DATA.'</th></tr>';
		} else {
			$x = 1;
			$num = 1;
			while ($row1 = mysql_fetch_object($qry1)) {
				$data = $x % 2;
				if ($data==0) {
					$dataX = "ganjil";
				} else {
					$dataX = "genap";
				} 
?>
  <tr valign="top" class="<?php echo $dataX; ?>" onmouseover="setBG('bg<?php echo $x; ?>','#FFFFDD')" onmouseout="setBG('bg<?php echo $x; ?>','')" id="bg<?php echo $x; ?>">
    <td>
	<div class="myHead">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="12" valign="middle"><img src="images/dir.png" width="16" height="16" />&nbsp;</td>
        <td width="200" valign="middle"><span align="left" title="URl : <?php echo $row1->url; ?>"><strong><?php echo $row1->dir_kat; ?></strong></span></td>
        </tr>
    </table>
	</div>	</td>
    <td width="100"><div align="center"><strong><?php echo $row1->id_dirkat; ?></strong></div></td>
    <td width="100"><div align="center"><strong><?php echo $row1->tipe; ?></strong></div></td>
    <td width="100"><div align="center"><?php (($row1->publish)==1) ? print "<img src=\"images/ico_check.gif\" width=\"16\" height=\"16\"></div></td>" : print "<img src=\"images/ico_delete.gif\" width=\"16\" height=\"16\"></div></td>";?></div></td>
	<?php echo $queryData->ctrl_data('','index.php?show='.SHOW.'&showview='.SHOWVIEW.'&act=edit&kode='.$row1->id_dirkat,$path.'ver_directory.php?show='.SHOW.'&amp;showview='.SHOWVIEW.'&amp;kode='.$row1->id_dirkat.'&amp;act_ver=Hapus'); ?>
  </tr>
  <tr valign="top" class="<?php echo $dataX; ?>" onmouseover="setBG('bg<?php echo $x; ?>','#FFFFDD')" onmouseout="setBG('bg<?php echo $x; ?>','')" id="bg<?php echo $x; ?>">
    <td colspan="5" style="padding:0; margin:0">
	<div class="myContent">
		<table width="100%" cellpadding="0" border="1" cellspacing="0">
<?php	
				$b = getSub($row1->id_dirkat,$dataX,2,$num);
				echo $b[0];
?>
		</table>
	</div>	</td>
    </tr>
<?php

				$num++;
				$x++;
			}  		
		}
?>
</table>
<?php
		echo $queryData->next_prev($num,$pages_syarat,$limitdown);
	}
?>